package org.example.lostandfound.service;

import org.example.lostandfound.dao.LostItemDao;
import org.example.lostandfound.model.LostItem;
import org.example.lostandfound.model.LostItemType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;
@Service
public class LostItemServiceImpl implements LostItemService {
    @Autowired
    private LostItemDao lostItemDao;

    @Override
    public List<LostItem> findAllLostItems() {
        return lostItemDao.findAllLostItems();
    }

    @Override
    public LostItem findLostItemById(Long id) {
        return lostItemDao.findLostItemById(id);
    }

    @Override
    public LostItem findLostItemByItemName(String itemName) {
        return lostItemDao.findLostItemByName(itemName);
    }

    @Override
    public void insertLostItem(LostItem lostItem) {
        lostItemDao.insertLostItem(lostItem);

    }

    @Override
    public void updateLostItem(LostItem lostItem) {
        lostItemDao.updateLostItem(lostItem);

    }

    @Override
    public void deleteLostItem(Long id) {
        lostItemDao.deleteLostItem(id);

    }

    @Override
    public List<LostItem> findLostItemsByFound(boolean found) {
        return lostItemDao.findLostItemsByFound(found);
    }

    @Override
    public List<LostItem> findLostItemsByType(LostItemType type) {
        return lostItemDao.findLostItemsByType(type);
    }
//用户申请领回丢失物品之后，将丢失物品的状态改变为已经被找到
    @Override
    public void foundLostItem(Long id) {
        LostItem lostItem = lostItemDao.findLostItemById(id);
        if (lostItem != null && !lostItem.isFound()) {
            lostItem.setFound(true);
            lostItemDao.updateLostItem(lostItem);
        }
    }
}
